package com.hmt.pharmacy.module.medicine.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hmt.pharmacy.api.medicine.SearchMedicineParamDto;
import com.hmt.pharmacy.api.medicine.SearchMedicineSelectParamDto;
import com.hmt.pharmacy.api.result.R;
import com.hmt.pharmacy.module.medicine.entity.Medicine;
import com.hmt.pharmacy.module.medicine.service.MedicineService;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
* <p>
    *  前端控制器
    * </p>
*
* @author 钟志豪
* @since 2025-06-25
*/
@RestController
@RequestMapping("/api")
public class MedicineController {

    @Autowired
    private MedicineService medicineService;

    @GetMapping("/medicine/list")
    public R<Page<Medicine>> list(@ModelAttribute SearchMedicineParamDto search) {
        Page<Medicine> page = medicineService.findPage(search);
        return R.ok(page);
    }

    @PostMapping("/medicine/data")
    public R saveData(@RequestBody Medicine entity) {
        medicineService.saveData(entity);
        return R.ok();
    }

    @PutMapping("/medicine/data")
    public R updateData(@RequestBody Medicine entity) {
        medicineService.updateData(entity);
        return R.ok();
    }

    @DeleteMapping("/medicine/data/{id}")
    public R delete(@PathVariable("id") String id) {
        medicineService.delete(id);
        return R.ok();
    }

    @GetMapping("/medicine/find/select/list")
    public R<Page<Medicine>> findSelectList(@ModelAttribute SearchMedicineSelectParamDto dto) {
        Page<Medicine> page = medicineService.findSelectList(dto);
        return R.ok(page);
    }

}